package com.example.yifei.ui.page.splash

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.*
import com.example.yifei.R
import kotlinx.coroutines.delay


/**
 * @Author: zhudaihao
 * @Date: 2022/5/6
 * @Describe: 启动页
 */

@Composable
fun SplashPage(onNextPage: () -> Unit) {
    Box(
        modifier = Modifier
            .fillMaxSize()
            .padding(bottom = 100.dp)
            .background(Color(0xff336AF8)),
        contentAlignment = Alignment.Center
    ) {
        //动画
        val composition by rememberLottieComposition(spec = LottieCompositionSpec.RawRes(R.raw.loading))
        val progress by animateLottieCompositionAsState(
            composition = composition,
            cancellationBehavior = LottieCancellationBehavior.OnIterationFinish
        )
        LottieAnimation(composition = composition, progress = progress)

        LaunchedEffect(Unit) {
            delay(3000)
            onNextPage.invoke()
        }

    }
}